package cn.wolfcode.exception;

import cn.wolfcode.qo.JsonResult;
import cn.wolfcode.util.UserContext;
import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.ResponseBody;

/**
 * @Author chenhui
 * @Date 2021/1/17 12:28
 **/

@ControllerAdvice
public class HandleException {

    @ResponseBody
    @ExceptionHandler(LogicException.class)
    public JsonResult Login(LogicException e){
        //获取登录次数
        int number = UserContext.getNumber();
        UserContext.setNumber(--number);
        if (number<1){
            if (number==0){
                UserContext.setTime();
                return new JsonResult(false,e.getMessage()+"你没了");
            }
            return new JsonResult(false,e.getMessage());
        }
        return new JsonResult(false,e.getMessage()+"还剩下"+number+"次");
    }
}
